<?php
//======================================================================================
//
// Function: Save a department
//
// Programmer: JKJ
// Date : 2021-11-03
//
// Copyright Reeft A/S (c) - 2021
//======================================================================================
//======================================================================================
// General config
//======================================================================================
include "config/config.php";
//======================================================================================
// Get input
//======================================================================================
if (isset($_REQUEST["mode"])) $mode = $_REQUEST["mode"];
else $mode = '';
if (isset($_REQUEST["data"])) {
$data = $_REQUEST["data"];
} else {
$data = 'hovsa';
}
if ( $mode == '' ) {
echo "There's no action....1";
exit;
}
if ( $mode <> '*add' and $mode <> '*update' ) {
echo "There's no action....2";
exit;
}
if ( $data == 'hovsa' ) {
echo "There's no data....";
exit;
}
//======================================================================================
// Convert from JSON
//======================================================================================
$json = json_decode($data);
$break = "\r\n";
$stringData = '<?xml version="1.0" encoding="UTF-8"?>' . $break;
$stringData .= '<data>' . $break;
foreach($json as $obj){
$key = $obj->name;
$value = $obj->value;
if ( $key == 'modal-input-pk_department') {
$pk_department = $value;
}
else if ( $key == 'modal-input-department_code') {
$department_code = $value;
}
else if ( $key == 'modal-input-department_name') {
$department_name = $value;
}
else if ( $key == 'modal-input-department_image') {
$department_image = $value;
}
else if ( $key == 'modal-input-department_color') {
$department_color = $value;
}
else if ( $key == 'modal-input-department_active') {
$department_active = $value;
}
}
//======================================================================================
// Get session variables
//======================================================================================
include "include/getsession.php";
//======================================================================================
// Set language
//======================================================================================
include "include/set_language.php";
//======================================================================================
// Connect to SQLite database in file
//======================================================================================
header('Content-Type: text/xml; charset=UTF-8');
$currentDate = date('Y-m-d');
$currentTime = date('H:i:s');
$xmlString = "<?xml version=\"1.0\"?>\n";
$xmlString .= "<data>\n";
//======================================================================================
// Connect to some DB
//======================================================================================
include "include/db_connect.php";
//======================================================================================
// Set active, token and other default values
//======================================================================================
if ( $department_code == '' ) {
$department_code = date("Y-m-d H:i:s");
$department_code = gmdate('Y-m-d H:i:s', strtotime($department_code));
}
//======================================================================================
// Create SQL
//======================================================================================
if ( $mode == '*update')
{
$sql = "update visual_department
set
department_code = '$department_code',
department_name = '$department_name',
department_image = '$department_image',
department_color = '$department_color',
department_active = '$department_active'
where pk_department = $pk_department
";
}
if ( $mode == '*add')
{
$sql = "INSERT INTO visual_department
(
department_code,
department_name,
department_image,
department_color,
department_active
)
VALUES (
'$department_code',
'$department_name',
'$department_image',
'$department_color',
'$department_active'
)
";
}
//echo $sql;
//======================================================================================
// Get data
//======================================================================================
include "include/db_run_sql.php";
//======================================================================================
// Check sql
//======================================================================================
if ( $current_elm == 0 ) {
$returnCode = '99';
$returnMsg = 'No data found';
} else {
$returnCode = '00';
$returnMsg = 'Alles ist gut';
}
//======================================================================================
// Create header
//======================================================================================
$xmlString .= "\t<header>\n";
$xmlString .= "\t\t<mode>" . $mode . "</mode>\n";
$xmlString .= "\t\t<last_pk_id>" . $last_id . "</last_pk_id>\n";
$xmlString .= "\t\t<rows_updated>" . $current_elm . "</rows_updated>\n";
$xmlString .= "\t\t<currentDate>" . $currentDate . "</currentDate>\n";
$xmlString .= "\t\t<currentTime>" . $currentTime . "</currentTime>\n";
$xmlString .= "\t\t<returnCode>" . $returnCode . "</returnCode>\n";
$xmlString .= "\t\t<returnMsg>" . $returnMsg . "</returnMsg>\n";
$xmlString .= "\t</header>\n";
//======================================================================================
// Paint it black
//======================================================================================
$xmlString = $xmlString . "</data>\n";
echo $xmlString;
?>